Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gen3] Fix LED behavior in case of network failure in Cloud Connecting state #2210

Merged
merged 1 commit into from
Oct 9, 2020

Conversation

keeramis
Copy link
Contributor

@keeramis keeramis commented Oct 6, 2020

Problem

When cloud connecting, the RGB LED doesn't go back to (blinking) green when de-registered from network, or when having DNS test failures

Solution

The cloud signaling procedure is correct, however, the LED doesn't reflect the same. The LED stays in blinking cyan, although the system state has backed off from "Cloud Connecting" state.

Steps to Test

  • Run any app that allows connecting to cloud, with serial logging enabled helpfully
  • As soon as "Cloud connecting" is seen (device must have started blinking cyan), disconnect the module from network (probably by removing antenna). This needs to be done after "Cloud: Connecting" and before "Cloud socket connected" states
  • The device struggles at that point to connect, and likely gets a CEREG: x deregistered URC
  • The device should be blinking green (instead of blinking cyan)

Example App

void setup() {
}

void loop() {
}

References

ch64095


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

@keeramis keeramis changed the title Network error to change led signaling [Gen3] Fix LED behavior in case of network loss after Cloud Connecting state Oct 6, 2020
if (connect_result == SYSTEM_ERROR_NETWORK) {
LED_SIGNAL_STOP(CLOUD_HANDSHAKE);
LED_SIGNAL_STOP(CLOUD_CONNECTING);
}
Copy link
Contributor Author

@keeramis keeramis Oct 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments:

  • Choosing to change LED behavior only with SYSTEM_ERROR_NETWORK because the other errors don't necessarily lead to network failure. As per my understanding, network failure should be the one case that should get the LED back to green.

  • The LED behavior also seem to largely depend on these states here such as these :

    LED_SIGNAL_START(NETWORK_CONNECTED, BACKGROUND);

    There is an edge case where the device enters "Cloud Connecting" state, and fails DNS test, but it has not yet gotten a deregistration URC, in which case it is in IP_CONFIGURED state so the above code makes it breathe green, which is rightfully the correct state because it is in IP_CONFIGURED state. Once it gets the deregistration URC, it blinks green as expected. Please see this log as well. Just highlighting an edge case for reference (and it looks OK from my understanding).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@sergeuz sergeuz Oct 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, this issue is specific to Gen 3 platforms. On Gen 2, the system gets notified that it's no longer connected to the network and proceeds to update the LED (as well as the system state) accordingly via a call to cloud_disconnect(): https://github.com/particle-iot/device-os/blob/develop/system/src/system_network_internal.h#L677-L680.

Perhaps, rather than providing a workaround for just one specific case, where creating the cloud socket or "connecting" it to the server fails (note that UDP sockets are connection-less), we should investigate why the system doesn't update the cloud connection state accordingly when it's no longer connected to the network? I think we have a bigger problem here rather than just LED indication, and it probably dates back to mesh times when we, for some reason, weren't able to determine reliably which network interface among the available ones is used for the cloud connection.

cc @avtolstoy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergeuz

investigate why the system doesn't update the cloud connection state accordingly

Which state should the system update the cloud connectivity status to? Probably go back to "cloud disconnect" and restart the connection since we see a +CEREG: 2 URC?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+CEREG: 2 cellular deregistration* URC.

Copy link
Member

@sergeuz sergeuz Oct 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discussed this PR with Andrey, and whereas it's possible that we're not cancelling the current ongoing connection attempt on network disconnection events in certain cases, trying to investigate and address that in the scope of this specific issue would be too much. The change introduced in this PR is perfectly fine: the establish_cloud_connection() function starts the LED indication and it should perform a cleanup and stop the indication if it wasn't able to establish a connection. I'm going to approve this PR 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okie thanks Sergey. Please let me know if we need to open a separate story for the broader correction.

@keeramis keeramis changed the title [Gen3] Fix LED behavior in case of network loss after Cloud Connecting state [Gen3] Fix LED behavior in case of network loss in Cloud Connecting state Oct 6, 2020
@keeramis keeramis changed the title [Gen3] Fix LED behavior in case of network loss in Cloud Connecting state [Gen3] Fix LED behavior in case of network failure in Cloud Connecting state Oct 6, 2020
@avtolstoy avtolstoy added this to the 2.0.0 milestone Oct 8, 2020
@keeramis keeramis requested a review from sergeuz October 9, 2020 15:17
@keeramis keeramis force-pushed the ch64095/blinks_cyan_when_disc branch from 43b12b6 to d7cc575 Compare October 9, 2020 18:35
@keeramis keeramis merged commit 1f2d369 into develop Oct 9, 2020
@keeramis keeramis deleted the ch64095/blinks_cyan_when_disc branch October 9, 2020 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants